package com.juhuixing.common.model;

import com.github.pagehelper.Page;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

/**
 *  返回的分页记录
 * Created by ioun on 2016/11/13.
 */
@Data
public class PageData<T> {

    @ApiModelProperty(value = "页码")
    int pageNo;
    @ApiModelProperty(value = "每页显示的记录数")
    int pageSize;
    @ApiModelProperty(value = "总记录数")
    long total;
    @ApiModelProperty(value = "总页数")
    int pages;
    @ApiModelProperty(value = "数据")
    List<T> data;

    /**
     * page转pageData
     * @param page
     * @param <T>
     * @return
     */
    public static <T>PageData getPageData(Page<T> page){
        PageData pageData = new PageData();
        pageData .setData(page.getResult());
        pageData.setPageNo(page.getPageNum());
        pageData.setPageSize(page.getPageSize());
        pageData.setTotal(page.getTotal());
        pageData.setPages(page.getPages());
        return  pageData;
    }
}
